﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeSoft.Application.Bussiness;
using LeSoft.Application.Cache;
using LeSoft.Application.Code;
using LeSoft.Application.Entity;
using LeSoft.Util;
using System.Collections;

namespace LeSoft.Application.Web.Areas.DailyEventManage.Controllers
{
    public class OpenShopController : MvcControllerBase
    {
        //
        // GET: /DailyEventManage/OpenShop/
        private DataItemDetailBLL dataItemDetailBLL = new DataItemDetailBLL();
        private TypeRoleBLL typeRoleBLL = new TypeRoleBLL();
        private PStructBLL pstructBLL = new PStructBLL();
        private CustomerInfoBLL customerInfoBLL = new CustomerInfoBLL();
        private DecorateBLL decorateBLL = new DecorateBLL();
        private ShopItemBLL shopItemBLL = new ShopItemBLL();
        private DepartmentBLL departmentBLL = new DepartmentBLL();
        private ShopItemObjectRelationBLL shopItemObjectRelationBLL = new ShopItemObjectRelationBLL();
        private CodeRuleBLL codeRuleBLL = new CodeRuleBLL();
        //private UserBLL userBLL = new UserBLL();
        private ShopBillBLL shopBillBLL = new ShopBillBLL();
        private SysTaskBLL sysTaskBLL = new SysTaskBLL();
        private DeviceBLL deviceBLL = new DeviceBLL();
        private ShopContentBLL shopContentBLL = new ShopContentBLL();
        #region 视图

        [HttpGet]
        [HandlerAuthorize(PermissionMode.Enforce)]
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        [HandlerAuthorize(PermissionMode.Enforce)]
        public ActionResult Form()
        {
            ViewBag.Mode = new CodeRuleBLL().CheckBillCodeMode(((int)CodeRuleEnum.OpenShopCode).ToString());
            return View();
        }
        [HttpGet]
        [HandlerAuthorize(PermissionMode.Enforce)]
        public ActionResult BatchForm()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize(PermissionMode.Enforce)]
        public ActionResult SendForm()
        {
            return View();
        }

        [HttpGet]
        [HandlerAuthorize(PermissionMode.Enforce)]
        public ActionResult TypeIndex()
        {
            return View();
        }

        public ActionResult TypeForm()
        {
            return View();
        }

        public ActionResult ItemIndex()
        {
            return View();
        }

        public ActionResult ItemForm()
        {
            return View();
        }

        public ActionResult ShopItemForm()
        {
            return View();
        }

        public ActionResult ContentIndex()
        {
            return View();
        }

        public ActionResult ContentForm()
        {
            return View();
        }

        public ActionResult ContentItemForm()
        {
            return View();
        }

        public ActionResult AddContent()
        {
            return View();
        }

        public ActionResult RegulatoryForm()
        {
            return View();
        }
        #endregion

        #region 查询数据
        [HttpGet]
        public ActionResult GetItemTreeListJson(string condition, string keyword, string EnCode)
        {
            var itemId = new DataItemBLL().GetEntity(EnCode, "").ItemId;
            var detailList = new DataItemDetailBLL().GetList(itemId).ToList();
            if (!string.IsNullOrEmpty(keyword))
            {
                #region 多条件查询
                switch (condition)
                {
                    case "ItemName":        //项目名
                        detailList = detailList.Where(t => t.ItemName.Contains(keyword)).ToList();
                        break;
                    case "ItemValue":      //项目值
                        detailList = detailList.Where(t => t.ItemValue.Contains(keyword)).ToList();
                        break;
                    case "SimpleSpelling": //拼音
                        detailList = detailList.Where(t => t.SimpleSpelling.Contains(keyword)).ToList();
                        break;
                    case "ItemCode": //拼音
                        detailList = detailList.Where(t => t.ItemCode.Contains(keyword)).ToList();
                        break;
                    default:
                        break;
                }
                #endregion
            }
            var typeRole = typeRoleBLL.GetList().Join(new PostBLL().GetAllList(), x => x.RoleId, y => y.RoleId, (x, y) => new
            {
                x.OrganizeId,
                x.NeedSortFlag,
                y.FullName,
                x.TypeId,
                x.Id
            });
            if (!OperatorProvider.Provider.Current().IsSystem)
            {
                typeRole = typeRole.Where(t => t.OrganizeId == OperatorProvider.Provider.Current().CompanyId);
            }
            var data = from x in detailList
                       join y in typeRole
                       on x.ItemDetailId equals y.TypeId into temp
                       from xy in temp.DefaultIfEmpty()
                       select new
                       {
                           x.ItemName,
                           x.ItemValue,
                           x.ItemCode,
                           x.SortCode,
                           x.ItemDetailId,
                           x.SimpleSpelling,
                           x.EnabledMark,
                           x.Description,
                           FullName = xy == null ? "" : xy.FullName,
                           NeedSortFlag = xy == null ? null : xy.NeedSortFlag,
                           TypeRoleId = xy == null ? null : xy.Id
                       };
            return Content(data.ToJson());
        }
        public ActionResult GetTypeRole(string keyValue)
        {
            var data = typeRoleBLL.GetEntity(keyValue);
            return Content(data.ToJson());
        }

        public ActionResult GetTypeRoleUser(string TypeId)
        {
            var dataType = typeRoleBLL.GetList(TypeId);
            var datarelation = new WorkerBLL().GetRelationList("");
            if (dataType != null && datarelation != null)
            {
                var dataUserId = from a in dataType join b in datarelation on a.RoleId equals b.ObjectId select new { b.UserId, b.Category, b.ObjectId };
                var dataworker = new WorkerBLL().GetList();
                if (dataUserId != null && dataworker != null)
                {
                    var data = from a in dataUserId join b in dataworker on new { id1 = a.UserId } equals new { id1 = b.Id } where a.Category == 3 select new { b.Name, b.Id };
                    return Content(data.ToJson());
                }
                else
                    return null;
            }
            else
                return null;
        }

        /// <summary>
        /// 获取数据字典列表（绑定控件）
        /// </summary>
        /// <param name="EnCode">代码</param>
        /// <returns>返回列表树Json</returns>
        [HttpGet]
        public ActionResult GetDataItemTreeJson(string EnCode)
        {
            var data = from x in new DataItemCache().GetDataItemList(EnCode)
                       join y in typeRoleBLL.GetList()
                       on x.ItemDetailId equals y.TypeId into temp
                       from xy in temp.DefaultIfEmpty()
                       select new
                       {
                           x.ItemDetailId,
                           x.ItemId,
                           x.ItemName,
                           x.ItemValue,
                           x.ParentId,
                           NeedSortFlag = xy != null ? xy.NeedSortFlag : null
                       };
            var treeList = new List<TreeEntity>();
            foreach (var item in data)
            {
                TreeEntity tree = new TreeEntity();
                bool hasChildren = data.Count(t => t.ParentId == item.ItemDetailId) == 0 ? false : true;
                tree.id = item.ItemDetailId;
                tree.text = item.ItemName;
                tree.value = item.ItemValue;
                tree.parentId = item.ParentId;
                tree.isexpand = true;
                tree.complete = true;
                tree.hasChildren = hasChildren;
                tree.Attribute = "NeedSortFlag";
                tree.AttributeValue = item.NeedSortFlag.ToString();
                treeList.Add(tree);
            }
            return Content(treeList.TreeToJson());
        }

        public ActionResult GetShopItemList(string TypeId, string organizeId, int Category, string ItemId = "")
        {
            var dataItem = shopItemBLL.GetList();
            if (!string.IsNullOrEmpty(TypeId))
            {
                dataItem = dataItem.Where(t => t.TypeId != TypeId);
            }
            if (!string.IsNullOrEmpty(organizeId))
            {
                dataItem = dataItem.Where(t => t.OrganizeId == organizeId);
            }
            if (!string.IsNullOrEmpty(ItemId))
            {
                dataItem = dataItem.Where(t => t.Id != ItemId);
            }
            var data = new object();
            var dataItemCache = new DataItemCache();
            if (Category == 1)
            {
                data = from x in dataItem
                       join y in dataItemCache.GetDataItemList("OpenShopType")
                           on x.CategoryId equals y.ItemDetailId into temp
                       from xy in temp.DefaultIfEmpty()
                       join c in departmentBLL.GetList() on x.ResponDepts equals c.DepartmentId
                           into temp1
                       from ac in temp1.DefaultIfEmpty()
                       select new
                       {
                           x.Id,
                           x.Category,
                           x.Code,
                           x.Name,
                           CategoryId = xy == null ? "" : xy.ItemName,
                           ResponDepts = ac == null ? "" : ac.FullName
                       };
            }
            else
            {
                data = from x in dataItem
                       join y in dataItemCache.GetDataItemList("CloseShopType")
                       on x.CategoryId equals y.ItemDetailId
                       into temp
                       from xy in temp.DefaultIfEmpty()
                       join c in departmentBLL.GetList()
                       on x.ResponDepts equals c.DepartmentId
                       into temp1
                       from ac in temp1.DefaultIfEmpty()
                       select new
                       {
                           x.Id,
                           x.Category,
                           x.Code,
                           x.Name,
                           CategoryId = xy == null ? "" : xy.ItemName,
                           ResponDepts = ac == null ? "" : ac.FullName
                       };
            }
            return Content(data.ToJson());
        }

        public ActionResult GetItemRelationList(string ItemId, int Category)
        {
            if (ItemId.IsEmpty())
                return null;
            else
            {
                var dataItem = new ShopItemManageRelationBLL().GetList(ItemId).Join(shopItemBLL.GetList(), x => x.MItemId, y => y.Id, (x, y) => new
                {
                    x.MItemId,
                    x.ItemId,
                    x.Id,
                    x.OrganizeId,
                    x.TypeId,
                    y.ResponDepts,
                    y.CategoryId,
                    y.Code,
                    y.Name
                });
                var data = new object();
                var dataItemCache = new DataItemCache();
                if (Category == 1)
                {
                    data = from x in dataItem
                           join y in dataItemCache.GetDataItemList("OpenShopType")
                               on x.CategoryId equals y.ItemDetailId into temp
                           from xy in temp.DefaultIfEmpty()
                           join c in departmentBLL.GetList() on x.ResponDepts equals c.DepartmentId
                               into temp1
                           from ac in temp1.DefaultIfEmpty()
                           select new
                           {
                               x.Id,
                               x.MItemId,
                               x.ItemId,
                               x.TypeId,
                               x.OrganizeId,
                               x.Code,
                               x.Name,
                               CategoryId = xy == null ? "" : xy.ItemName,
                               ResponDepts = ac == null ? "" : ac.FullName
                           };
                }
                else
                {
                    data = from x in dataItem
                           join y in dataItemCache.GetDataItemList("CloseShopType")
                           on x.CategoryId equals y.ItemDetailId
                           into temp
                           from xy in temp.DefaultIfEmpty()
                           join c in departmentBLL.GetList()
                           on x.ResponDepts equals c.DepartmentId
                           into temp1
                           from ac in temp1.DefaultIfEmpty()
                           select new
                           {
                               x.Id,
                               x.MItemId,
                               x.ItemId,
                               x.TypeId,
                               x.OrganizeId,
                               x.Code,
                               x.Name,
                               CategoryId = xy == null ? "" : xy.ItemName,
                               ResponDepts = ac == null ? "" : ac.FullName
                           };
                }
                return Content(data.ToJson());
            }
        }

        /// <summary>
        /// 查询内容实体
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public ActionResult GetContentJson(string keyValue)
        {
            var data = shopContentBLL.GetEntity(keyValue);
            return Content(data.ToJson());
        }

        public ActionResult GetContentList(string ids)
        {
            var dataLine = shopContentBLL.GetList();
            //if (!OperatorProvider.Provider.Current().IsSystem)
            //{
            //    var organizeids = new OrganizeCache().GetSonOrganizeId(OperatorProvider.Provider.Current().CompanyId);
            //    dataLine = dataLine.Where(t => t.OrganizeId != null && organizeids.Contains(t.OrganizeId)).ToList();
            //}
            if (!string.IsNullOrEmpty(ids)) dataLine = dataLine.Where(t => ids.Contains(t.Id)).ToList();
            return Content(dataLine.ToJson());
        }

        public ActionResult GetShopItemPageListJson(Pagination pagination, string queryJson)
        {
            var watch = CommonHelper.TimerStart();
            var queryParam = queryJson.ToJObject();
            var dataType = dataItemDetailBLL.GetList(queryParam["TypeId"].ToString());
            var dataItem = shopItemBLL.GetPageList(pagination, queryJson).Join(dataType, x => x.TypeId, y => y.ItemDetailId, (x, y) => new { x.Id, x.Name, x.ResponDepts, x.Code, x.Criterion, y.ItemName, x.BeginTime, x.EndTime });
            var dataDepartment = departmentBLL.GetList();
            var data = from x in dataItem
                       join c in departmentBLL.GetList()
                       on x.ResponDepts equals c.DepartmentId
                       into temp1
                       from ac in temp1.DefaultIfEmpty()
                       select new
                       {
                           x.Id,
                           x.Name,
                           x.ResponDepts,
                           x.Code,
                           x.Criterion,
                           x.BeginTime,
                           x.EndTime,
                           x.ItemName,
                           FullName = ac == null ? "" : ac.FullName
                       };
            var JsonData = new
            {
                rows = data,
                total = pagination.total,
                page = pagination.page,
                records = pagination.records,
                costtime = CommonHelper.TimerEnd(watch)
            };
            return Content(JsonData.ToJson());
        }

        public ActionResult GetItemObject(string ItemId)
        {
            if (ItemId.IsEmpty())
                return null;
            else
            {
                var data = shopItemObjectRelationBLL.GetList(ItemId);
                return Content(data.ToJson());
            }

        }
        public ActionResult GetItemObjectList(string ItemId)
        {
            if (ItemId.IsEmpty())
                return null;
            else
            {
                var dataItemObject = shopItemObjectRelationBLL.GetList(ItemId).OrderBy(t => t.SortCode); 
                var list = new ArrayList();
                foreach (var item in dataItemObject)
                {
                    var onj = new
                    {
                        item.Id,
                        Name = item.ObjectName,
                        
                        Code =item.ObjectTypeId == 0 ? new PStructBLL().GetEntity(item.ObjectId).Code : item.ObjectTypeId == 1 ? new CustomerInfoBLL().GetEntity(item.ObjectId).Code:item.ObjectTypeId == 2 ?new PStructBLL().GetEntity(item.ObjectId).Code:item.ObjectTypeId == 3?new DeviceBLL().GetEntity(item.ObjectId).Code:item.ObjectTypeId == 4 ? new DecorateBLL().GetEntity(item.ObjectId).Code: item.ObjectTypeId == 5 ? new  ShopContentBLL().GetEntity(item.ContentId).Code: "",                     
                        ObjectTypeName = item.ObjectTypeId == 0 ? "房间" : item.ObjectTypeId == 1 ? "商户" : item.ObjectTypeId == 2 ? "公共部位" : item.ObjectTypeId == 3 ? "设备" : item.ObjectTypeId == 4 ? "装修现场" : item.ObjectTypeId == 5 ? "内容" : "",
                        item.ObjectTypeId,
                        item.PictureFlag,
                        item.ObjectId,
                        item.ContentId,
                        item.SortCode,
                        item.ItemId
                    };
                    list.Add(onj);
                }
                return Content(list.ToJson());
            }
        }

        public ActionResult GetContent(string queryJson)
        {
            var data = shopContentBLL.GetList(queryJson);
            return Content(data.ToJson());
        }

        public ActionResult GetObject(int Type, string organizeId, string keyword)
        {
            var data = new object();
            switch (Type)
            {
                case 0: data = !string.IsNullOrEmpty(keyword) ? pstructBLL.GetList().Where(t => t.Type == 5 && t.OrganizeId == organizeId && (t.Code.Contains(keyword) || t.Name.Contains(keyword))) : pstructBLL.GetList().Where(t => t.Type == 5 && t.OrganizeId == organizeId); break;
                case 1: data = !string.IsNullOrEmpty(keyword) ? customerInfoBLL.GetList().Where(t => t.Name != null && t.OrganizeId == organizeId && (t.Code.Contains(keyword) || t.Name.Contains(keyword))) : customerInfoBLL.GetList().Where(t => t.Name != null && t.OrganizeId == organizeId); break;
                case 2: {
                    data = !string.IsNullOrEmpty(keyword)
                           ? pstructBLL.GetList().Where(t => t.Type == 6 && t.OrganizeId == organizeId && (t.Code.Contains(keyword) || t.Name.Contains(keyword))).Join(new PollingBLL().GetList(), x => x.Id, y => y.PStructID, (x, y) => new { x.Id,x.Name,y.OtherCode})
                           : pstructBLL.GetList().Where(t => t.Type == 6 && t.OrganizeId == organizeId).Join(new PollingBLL().GetList(), x => x.Id, y => y.PStructID, (x, y) => new { x.Id, x.Name, y.OtherCode });
                } ;break;
                case 3: data = !string.IsNullOrEmpty(keyword) ? deviceBLL.GetList().Where(t => t.EnabledMark == 1 && (t.Name.Contains(keyword) || t.Code.Contains(keyword)) && t.OrganizeId == organizeId) : deviceBLL.GetList().Where(t => t.EnabledMark == 1 && t.OrganizeId == organizeId); break;
                case 4: data = !string.IsNullOrEmpty(keyword) ? pstructBLL.GetList().Where(t => t.OrganizeId == organizeId && (t.Code.Contains(keyword) || t.Name.Contains(keyword))).Join(decorateBLL.GetList(-1, "").Where(t => t.State > 2 && t.PBeginDate > DateTime.Now), x => x.Id, y => y.PStructId, (x, y) => new { x.Id, x.Name, x.Code }) : pstructBLL.GetList().Where(t => t.OrganizeId == organizeId).Join(decorateBLL.GetList(-1, "").Where(t => t.State > 2 && t.PBeginDate > DateTime.Now), x => x.Id, y => y.PStructId, (x, y) => new { x.Id, x.Name, x.Code }); break;
                default: break;
            }
            return Content(data.ToJson());
        }

        public ActionResult GetItemEntity(string keyValue)
        {
            var data = shopItemBLL.GetEntity(keyValue);
            return Content(data.ToJson());
        }

        public ActionResult GetTask(string SourceId)
        {
            var data = sysTaskBLL.GetSourceIdByEntity(SourceId);
            return Content(data.ToJson());
        }

        public ActionResult GetPageListShopBill(Pagination pagination, DateTime StartTime, DateTime EndTime, string Type, int Billtype, string organizeid)
        {
            var watch = CommonHelper.TimerStart();
            var dataShop = shopBillBLL.GetPageList(pagination, StartTime, EndTime, Billtype, Type);
            if (!string.IsNullOrEmpty(organizeid)) dataShop = dataShop.Where(t => t.OrganizeId == organizeid);
            var dataTask = sysTaskBLL.GetList();
            var data = from x in dataShop
                       join y in dataTask
                       on x.Id equals y.SourceId into temp
                       from xy in temp.DefaultIfEmpty()
                       select new
                       {
                           x.Id,
                           x.State,
                           x.Type,
                           x.TypeId,
                           x.Date,
                           x.AuditMark,
                           x.Code
                       };
            var JsonData = new
                       {
                           rows = data,
                           total = pagination.total,
                           page = pagination.page,
                           records = pagination.records,
                           costtime = CommonHelper.TimerEnd(watch)
                       };
            return Content(JsonData.ToJson());
        }

        public ActionResult GetShopBillEntity(string keyValue)
        {
            var data = shopBillBLL.GetEntity(keyValue);
            return Content(data.ToJson());
        }

        public ActionResult GetItemResult(string BillId)
        {
            var data = new ShopBillDetailBLL().GetList(BillId).GroupBy(t => t.ItemId).Select(t => new
            {
                Id = t.First().Id,
                ItemId = t.First().ItemId,
                BillId = t.First().BillId,
                CompleteState = t.Count(a => a.CompleteState == 0 || a.CompleteState == null) == 0 ? 1 : 0
            }).Join(shopItemBLL.GetList(), x => x.ItemId, y => y.Id, (x, y) => new
            {
                x.Id,
                x.ItemId,
                x.BillId,
                y.BeginTime,
                y.EndTime,
                x.CompleteState,
                y.Criterion,
                y.Code,
                ItemName = y.Name,
                y.ResponDepts
            });
            var dataDepartment = departmentBLL.GetList();
            var dataList = from x in data
                           join c in departmentBLL.GetList()
                           on x.ResponDepts equals c.DepartmentId
                           into temp1
                           from ac in temp1.DefaultIfEmpty()
                           select new
                           {
                               x.Id,
                               x.ItemId,
                               x.ItemName,
                               x.BeginTime,
                               x.EndTime,
                               x.BillId,
                               x.CompleteState,
                               x.Code,
                               x.Criterion,
                               FullName = ac == null ? "" : ac.FullName
                           };
            return Content(data.ToJson());
        }

        public ActionResult GetObjectResult(string BillId, string ItemId)
        {
            var data = new ShopBillDetailBLL().GetList(BillId).Where(t => t.ItemId == ItemId).Join(shopItemObjectRelationBLL.GetList(ItemId), x => x.SIOCId, y => y.Id, (x, y) => new
            {
                x.Id,
                x.BillId,
                x.CompleteState,
                x.CompleteMan,
                x.CompleteDate,
                y.ObjectName,
                y.ObjectTypeId,
                y.ContentId,
                y.PictureFlag
            });
            return Content(data.ToJson());
        }
        #endregion

        #region 保存数据

        /// <summary>
        /// 保存工作类型表单（新增、修改）
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="dataItemDetailEntity">明细实体</param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult TypeSaveForm(string keyValue, string EnCode, DataItemDetailEntity dataItemDetailEntity, TypeRoleRelationEntity typeRoleRelationEntity)
        {
            var itemId = new DataItemBLL().GetEntity(EnCode, "").ItemId;
            dataItemDetailEntity.ItemId = itemId;
            dataItemDetailBLL.SaveForm(keyValue, dataItemDetailEntity, typeRoleRelationEntity);
            return Success("操作成功。");
        }

        /// <summary>
        /// 保存工作项目表单（新增、修改）
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="dataItemDetailEntity">明细实体</param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult ItemSaveForm(string keyValue, string shopItemStr, string obj, string mItemStr)
        {
            ShopItemEntity shopItemEntity = shopItemStr.ToObject<ShopItemEntity>();
            List<ShopItemObjectRelationEntity> list = obj.ToObject<List<ShopItemObjectRelationEntity>>();
            List<ShopItemManageRelationEntity> mlist = mItemStr.ToObject<List<ShopItemManageRelationEntity>>();
            shopItemBLL.SaveForm(keyValue, shopItemEntity, list, mlist);
            return Success("操作成功。");
        }

        /// <summary>
        /// 删除工作项目表单（新增、修改）
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="dataItemDetailEntity">明细实体</param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult ItemRemoveForm(string keyValue)
        {
            shopItemBLL.RemoveForm(keyValue);
            return Success("操作成功。");
        }

        /// <summary>
        /// 删除工作单（新增、修改）
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="dataItemDetailEntity">明细实体</param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult RemoveForm(string keyValue)
        {
            shopBillBLL.RemoveForm(keyValue);
            return Success("操作成功。");
        }

        /// <summary>
        /// 保存工作项目表单（新增、修改）
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="dataItemDetailEntity">明细实体</param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult ShopBillSaveForm(string keyValue, string ShopBill, string ShopBillDetail, string Task, string TaskUser)
        {
            ShopBillEntity shopBillEntity = ShopBill.ToObject<ShopBillEntity>();
            List<ShopBillDetailEntity> listShopBillDetail = ShopBillDetail.ToObject<List<ShopBillDetailEntity>>();
            //if (listShopBillDetail.Count < 1)
            //{
            //    return Error("未取到工作内容。");
            //}
            //else
            //{
            shopBillBLL.SaveForm(keyValue, shopBillEntity, listShopBillDetail);
            if (Task != "{}" && TaskUser != "[]")
            {
                SysTaskEntity taskEntity = Task.ToObject<SysTaskEntity>();
                List<SysTaskUserEntity> listTaskUser = TaskUser.ToObject<List<SysTaskUserEntity>>();
                shopBillBLL.SendBill(keyValue, taskEntity, listTaskUser);
            }
            return Success("操作成功。");
            //}


        }


        /// <summary>
        /// 批量生成工单
        /// </summary>
        /// <param name="keyValue"></param>
        /// <param name="ShopBill"></param>
        /// <param name="ShopBillDetail"></param>
        /// <param name="Task"></param>
        /// <param name="TaskUser"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult BatchSaveForm(string ShopStr)
        {
            try
            {
                shopBillBLL.CreateBills(ShopStr);
                return Success("操作成功。");
            }
            catch (Exception e)
            {
                return Error(e.Message);
            }
        }

        /// <summary>
        /// 保存内容
        /// </summary>
        /// <param name="keyValue"></param>
        /// <param name="pollingItemEntity"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult SaveContentForm(string keyValue, ShopContentEntity shopContentEntity)
        {
            shopContentBLL.SaveForm(keyValue, shopContentEntity);
            return Success("操作成功。");
        }
        /// <summary>
        /// 删除内容
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult RemoveContentForm(string keyValue)
        {
            shopContentBLL.RemoveForm(keyValue);
            return Success("删除成功。");
        }

        #endregion

    }
}
